
let dataHtml = "";
layui.config({
    version: '1510164124181'
}).use(['form', 'laypage', 'layer', 'element'], function () {
    form = layui.form;
    layer = layui.layer;
    $ = layui.jquery;
    laypage = layui.laypage;//分页
    element = layui.element; //元素操作
    inituserdata();

});


function inituserdata() {
    let SelectInfo = $("#ClassifyList option:selected").val();
    let InputInfo = $("#SearchInfo").val();

    let type = $("#type option:selected").val();
    // console.log(SelectInfo + "=====" + InputInfo + "===" + pageNo + "====" + pageRecords);

    dataHtml = "";
    $("#tableInfo tbody").html("");

    $.ajax({
        url: httpurl + "/callHTS",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType : 'application/json',
        data: {
            "page": pageNo,
            "pagesize": pageRecords,
            "type": type,
            "enable": SelectInfo,
            "name": InputInfo,
        },
        // dataType: "json",
        success: function (data) {
            // console.log("====" + JSON.stringify(data));

            if (data.rtnCode == 200) {
                let dataList = data.data;
                totalRecords = dataList[dataList.length-1].total;
                let tempInfo='无';
                for (let i = 0; i < dataList.length; i++) {
                    if(dataList[i].type == 2){
                        tempInfo='<img width="80" src="'+visitimgurl+"/"+dataList[i].pimg+'" />';
                    }
                    dataHtml += '<tr>' +
                        '<td><input data-id="' + dataList[i].id + '" type="checkbox"  name="box" class="aceChild"/></td>' +
                        '<td>' + (dataList[i].type == 1 ? "天兰头条分类" : (dataList[i].type == 2 ? "商品分类" : (dataList[i].type == 3 ? "优惠券类型" : ""))) + '</td>' +
                        '<td>'+tempInfo+'</td>' +
                        '<td>' + dataList[i].name + '</td>' +
                        '<td>' + (dataList[i].enable == '1' ? "是" : "否") + '</td>' +
                        '<td>' + dataList[i].sort + '</td>' +
                        '<td><a href="AddClassifyList.html?ActicleTypeId=' + dataList[i].id + '">编辑</a>&nbsp;&nbsp;' +
                        // '<a href="#" data-id="' + dataList[i].id + '" data-info="deletedTypeList" onclick="DeleteInfo(this)">删除</a>' +
                        '</td>' +
                        '</tr>';
                }
            } else if (data.rtnCode == 500) {
                totalRecords = 0;
                dataHtml += '<tr>'
                    + '<td colspan="12" style="text-align:center;">暂无数据</td>'
                    + '</tr>';
            }
            $("#tableInfo tbody").html(dataHtml);
            layer.closeAll();
            page();
        }

    });

}


//分页
function page() {
    laypage.render({
        elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
        , count: totalRecords //数据总数，从服务端得到
        , curr: pageNo //获取起始页 location.hash.replace('#!fenye=', '')
        , hash: 'fenye' //自定义hash值
        , layout: ['count', 'prev', 'page', 'next', 'skip']
        , jump: function (obj, first) {
            //首次不执行
            if (!first) {
                pageNo = obj.curr;// 当前页数;
                pageRecords = obj.limit;// 当前页面记录数
                inituserdata();
            }
        }
    });
}

function SearchInfo() {
    pageNo = 1;
    inituserdata();
}
